﻿function CloseUpLoal(){
    $("#fileUploadContent").empty();
    $(".popup_box_cover").hide();
}

$(function () {

    $(".am-form-group .twoBox span").click(function (e) {
        var typ = $(this).attr("trd");
        var num = 1;
        if ("firstIdentity" == typ) { //身份证正面上传
            $(".popup_box h3").text("上传身份证正面").attr("trd", typ);
        }
        else if ("secondIdentity" == typ) { //身份证反面上传
            $(".popup_box h3").text("上传身份证反面").attr("trd", typ);
        }
        else if ("BankCard" == typ) { //银行卡上传
            $(".popup_box h3").text("上传银行卡").attr("trd", typ);
        }
        else {
        }

        $("#fileUploadContent").initUpload({
            "uploadUrl": "/NoticeOper.ashx?action=upload",//上传文件信息地址
            "size": 1024,//文件大小限制，单位kb,默认不限制
            "maxFileNumber": num,//文件个数限制，为整数
            // "filelSavePath": $(".popup_box h3").attr("trd"),//文件上传地址，后台设置的根目录
            "beforeUpload": beforeUploadFun,//在上传前执行的函数
            "onUpload": onUploadFun,//在上传后执行的函数
            //autoCommit:true,//文件是否自动上传
            "fileType": ['jpg','png']//文件类型限制，默认不限制，注意写的是文件后缀
        });
        $(".popup_box_cover").show();
    });

    $(".popup_box_cover .popup_box span").click(function (e) {
        CloseUpLoal();
    });
});


function beforeUploadFun(opt) {
    var fileType = ".jpg";
    if (0 < opt.fileList.length) {
        if (-1 < opt.fileList[0].name.indexOf("png"))
            fileType = ".png";
        opt.otherData = [{ "name": "accountMsg", "value": $(".popup_box h3").attr("accountMsg") },
        { "name": "uploadtype", "value": $(".popup_box h3").attr("trd") },
        { "name": "fileType", "value": fileType },
        { "name": "action", "value": "upload" }];
    }
}
function onUploadFun(opt, data) {
    if (-1 <  data.indexOf("ok")) {
        uploadTools.uploadSuccess(opt);//显示上传成功
        $('.am-form-group .twoBox span[trd="' + data.split('_')[1] + '"]').text("已上传").attr("disabled", true);
        alert("上传成功!");
        CloseUpLoal();
    }
    else {
        uploadTools.uploadError(opt);//显示上传错误
        alert("上传失败!" + data);
    }
}

function OnClickCheckBtn(thisObj) {
    var listSpan = $('.am-form-group .twoBox span[disabled="disabled"]');
    if (5 != listSpan.length) {
        alert("请上传身份证或银行卡后再提交!");
    }
    else {
        $.post("/NoticeOper.ashx?action=submitinfo", null, function (data) {
            if (-1 < data.indexOf("ok")) {
                $(".am-form-group .topTip p").text("资料审核中,请稍等.");
                $(thisObj).text("审核中").attr("disabled", true);
            }
            else {
                alert("提交失败!  " + data);
            }
        });
    }
}